﻿using Omu.AwesomeDemo.Core.Model;
using Omu.AwesomeDemo.Core.Repository;
using Omu.AwesomeDemo.Infra.Dto;

namespace Omu.AwesomeDemo.Infra.Builder
{
    public class FoobarBuilder : Builder<Foobar, FoobarInput>
    {
        public FoobarBuilder(IRepo<Foobar> repo)
            : base(repo)
        {
        }

        protected override void MakeEntity(ref Foobar entity, FoobarInput input)
        {
            if(!string.IsNullOrWhiteSpace(input.Hobby))
            entity.Hobby = new Hobby { Name = input.Hobby, Id = input.HobbyId.HasValue ? input.HobbyId.Value : 0 };
        }

        protected override void MakeInput(Foobar entity, ref FoobarInput input)
        {
            if (entity.Hobby == null) return;
            input.Hobby = entity.Hobby.Name;
            input.HobbyId = entity.Hobby.Id;
        }
    }
}